package mongo.db.clients.firsts;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.mongodb.MongoClient;

public class NetflowGenMain {

	public static void main(String[] args) {
		
		ExecutorService routerExeService = Executors.newFixedThreadPool(500);
		
		MongoClient client = null;
		try {
			client = new MongoClient("202.191.136.234", 27017);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		
		Date startTime = new Date();
		int count = 2000;

		List<Future<Integer>> futureList = new ArrayList<Future<Integer>>();
		for (int i = 300000; i < 900000; i += count) {
			NetflowGen threadObj = new NetflowGen(i, count, client);
			futureList.add(routerExeService.submit(threadObj));
		}

		try {
			for (Future<Integer> future : futureList) {
				future.get();
			}
		} catch (Exception e) {
			System.out.println("Aggregator : " + e);
		}

		Date endTime = new Date();
		
		System.out.println("jobs successfully completed : " + futureList.size());
		futureList.clear();
		System.out.println("executor service shutting down....");
		routerExeService.shutdown();
		System.out.println("total time taken : " + (endTime.getTime() - startTime.getTime()));
		
	}

}
